package com.fenghongzhang.day005;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class MainActivity extends AppCompatActivity {
    private LinearLayout ll;
    private RadioGroup group;
    private RadioButton person;
    private RadioButton info;

    private InfoFragment infoFragment;
    private PersonFragment personFragment;
    private FragmentManager supportFragmentManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        ll = (LinearLayout) findViewById(R.id.ll);
        group = (RadioGroup) findViewById(R.id.group);
        person = (RadioButton) findViewById(R.id.person);
        info = (RadioButton) findViewById(R.id.info);


        supportFragmentManager = getSupportFragmentManager();
        final FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction();
         personFragment = new PersonFragment();
         infoFragment = new InfoFragment();
        fragmentTransaction.add(R.id.ll,personFragment);
        fragmentTransaction.addToBackStack(null);

//        fragmentTransaction.add(R.id.ll,infoFragment);
        fragmentTransaction.commit();



//        group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(RadioGroup group, int checkedId) {
//                //点击谁,谁显示.另一个消失
//                switch (checkedId){
//                    case R.id.person:
//                        FragmentTransaction fragmentTransaction1 = supportFragmentManager.beginTransaction();
//                        fragmentTransaction1.hide(infoFragment);
//                        fragmentTransaction1.show(personFragment);
//                        fragmentTransaction1.commit();
//                        break;
//
//                    case R.id.info:
//                        FragmentTransaction fragmentTransaction2 = supportFragmentManager.beginTransaction();
//                        fragmentTransaction2.hide(personFragment);
//                        fragmentTransaction2.show(infoFragment);
//                        fragmentTransaction2.commit();
//                        break;
//                }
//            }
//        });

    }
}
